home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_filecmp.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  5KB  |  161 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import os
  5. import filecmp
  6. import shutil
  7. import tempfile
  8. import unittest
  9. from test import test_support
  10.  
  11. class FileCompareTestCase(unittest.TestCase):
  12.     
  13.     def setUp(self):
  14.         self.name = test_support.TESTFN
  15.         self.name_same = test_support.TESTFN + '-same'
  16.         self.name_diff = test_support.TESTFN + '-diff'
  17.         data = 'Contents of file go here.\n'
  18.         for name in [
  19.             self.name,
  20.             self.name_same,
  21.             self.name_diff]:
  22.             output = open(name, 'w')
  23.             output.write(data)
  24.             output.close()
  25.         
  26.         output = open(self.name_diff, 'a+')
  27.         output.write('An extra line.\n')
  28.         output.close()
  29.         self.dir = tempfile.gettempdir()
  30.  
  31.     
  32.     def tearDown(self):
  33.         os.unlink(self.name)
  34.         os.unlink(self.name_same)
  35.         os.unlink(self.name_diff)
  36.  
  37.     
  38.     def test_matching(self):
  39.         self.failUnless(filecmp.cmp(self.name, self.name_same), 'Comparing file to itself fails')
  40.         self.failUnless(filecmp.cmp(self.name, self.name_same, shallow = False), 'Comparing file to itself fails')
  41.         self.failUnless(filecmp.cmp(self.name, self.name, shallow = False), 'Comparing file to identical file fails')
  42.         self.failUnless(filecmp.cmp(self.name, self.name), 'Comparing file to identical file fails')
  43.  
  44.     
  45.     def test_different(self):
  46.         self.failIf(filecmp.cmp(self.name, self.name_diff), 'Mismatched files compare as equal')
  47.         self.failIf(filecmp.cmp(self.name, self.dir), 'File and directory compare as equal')
  48.  
  49.  
  50.  
  51. class DirCompareTestCase(unittest.TestCase):
  52.     
  53.     def setUp(self):
  54.         tmpdir = tempfile.gettempdir()
  55.         self.dir = os.path.join(tmpdir, 'dir')
  56.         self.dir_same = os.path.join(tmpdir, 'dir-same')
  57.         self.dir_diff = os.path.join(tmpdir, 'dir-diff')
  58.         self.caseinsensitive = os.path.normcase('A') == os.path.normcase('a')
  59.         data = 'Contents of file go here.\n'
  60.         for dir in [
  61.             self.dir,
  62.             self.dir_same,
  63.             self.dir_diff]:
  64.             os.mkdir(dir)
  65.             if self.caseinsensitive and dir is self.dir_same:
  66.                 fn = 'FiLe'
  67.             else:
  68.                 fn = 'file'
  69.             output = open(os.path.join(dir, fn), 'w')
  70.             output.write(data)
  71.             output.close()
  72.         
  73.         output = open(os.path.join(self.dir_diff, 'file2'), 'w')
  74.         output.write('An extra file.\n')
  75.         output.close()
  76.  
  77.     
  78.     def tearDown(self):
  79.         shutil.rmtree(self.dir)
  80.         shutil.rmtree(self.dir_same)
  81.         shutil.rmtree(self.dir_diff)
  82.  
  83.     
  84.     def test_cmpfiles(self):
  85.         self.failUnless(filecmp.cmpfiles(self.dir, self.dir, [
  86.             'file']) == ([
  87.             'file'], [], []), 'Comparing directory to itself fails')
  88.         self.failUnless(filecmp.cmpfiles(self.dir, self.dir_same, [
  89.             'file']) == ([
  90.             'file'], [], []), 'Comparing directory to same fails')
  91.         self.failUnless(filecmp.cmpfiles(self.dir, self.dir, [
  92.             'file'], shallow = False) == ([
  93.             'file'], [], []), 'Comparing directory to itself fails')
  94.         self.failUnless(filecmp.cmpfiles(self.dir, self.dir_same, [
  95.             'file'], shallow = False), 'Comparing directory to same fails')
  96.         output = open(os.path.join(self.dir, 'file2'), 'w')
  97.         output.write('Different contents.\n')
  98.         output.close()
  99.         self.failIf(filecmp.cmpfiles(self.dir, self.dir_same, [
  100.             'file',
  101.             'file2']) == ([
  102.             'file'], [
  103.             'file2'], []), 'Comparing mismatched directories fails')
  104.  
  105.     
  106.     def test_dircmp(self):
  107.         d = filecmp.dircmp(self.dir, self.dir_same)
  108.         if self.caseinsensitive:
  109.             self.assertEqual([
  110.                 d.left_list,
  111.                 d.right_list], [
  112.                 [
  113.                     'file'],
  114.                 [
  115.                     'FiLe']])
  116.         else:
  117.             self.assertEqual([
  118.                 d.left_list,
  119.                 d.right_list], [
  120.                 [
  121.                     'file'],
  122.                 [
  123.                     'file']])
  124.         self.failUnless(d.common == [
  125.             'file'])
  126.         None(self.failUnless if d.right_only == d.right_only else d.right_only == [])
  127.         self.failUnless(d.same_files == [
  128.             'file'])
  129.         self.failUnless(d.diff_files == [])
  130.         d = filecmp.dircmp(self.dir, self.dir_diff)
  131.         self.failUnless(d.left_list == [
  132.             'file'])
  133.         self.failUnless(d.right_list == [
  134.             'file',
  135.             'file2'])
  136.         self.failUnless(d.common == [
  137.             'file'])
  138.         self.failUnless(d.left_only == [])
  139.         self.failUnless(d.right_only == [
  140.             'file2'])
  141.         self.failUnless(d.same_files == [
  142.             'file'])
  143.         self.failUnless(d.diff_files == [])
  144.         output = open(os.path.join(self.dir, 'file2'), 'w')
  145.         output.write('Different contents.\n')
  146.         output.close()
  147.         d = filecmp.dircmp(self.dir, self.dir_diff)
  148.         self.failUnless(d.same_files == [
  149.             'file'])
  150.         self.failUnless(d.diff_files == [
  151.             'file2'])
  152.  
  153.  
  154.  
  155. def test_main():
  156.     test_support.run_unittest(FileCompareTestCase, DirCompareTestCase)
  157.  
  158. if __name__ == '__main__':
  159.     test_main()
  160.  
  161.